package com.ziiwee.reduce.describe.creators.fields;

import org.springframework.core.ResolvableType;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author ziiwee
 * @data 2020/8/12
 */
public class ParameterFieldDescribeCreator extends AbstractFieldDescribeCreator{

    private final Parameter parameter;
    private final ResolvableType resolvableType;
    private final String name;

    public ParameterFieldDescribeCreator(Method method, int index, String name) {
        this.resolvableType = ResolvableType.forMethodParameter(method, index);
        this.parameter = method.getParameters()[index];
        this.name = name;
    }

    @Override
    public AnnotatedElement getElement() {
        return parameter;
    }

    @Override
    public ResolvableType getDefaultType() {
        return resolvableType;
    }

    @Override
    public String getName() {
        return name;
    }
}
